package com.leff.cards.data;

import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;

import android.util.Log;

import com.leff.cards.util.Secrets;
import com.leff.cards.util.Dictionary;

public class ResponseCard extends AbstractCard implements Secrets {

	private long mId;
	private String mText;
	
	private ResponseCard() {
	}
	
	public long getId() {
		return mId;
	}
	public String getText() {
		return mText;
	}
	
	public static ResponseCard fromDictionary(Dictionary dict) {
		
		ResponseCard rc = new ResponseCard();
		
		rc.mId = (Long)dict.get("id");
		rc.mText = (String)dict.get("text");
		
		return rc;
	}
	
	public static ResponseCard fromJSONString(String json) {
		
		JSONParser parser = new JSONParser();
		
		ResponseCard rc = new ResponseCard();
		
		try {
			JSONObject obj = (JSONObject)parser.parse(json);
			
			rc.mId = (Long)obj.get("id");
			rc.mText = (String)obj.get("text");
			
		} catch(Exception e) {
			Log.v(TAG, "Error Parsing Server Response:", e);
		}
		return rc;
	}
}
